package ajaxjs.service.webservice;

import javax.servlet.http.HttpServletRequest;
import ajaxjs.net.Request;
/**
 * 接口层
 * 
 * 	if(request.getParameter("getLocationByIP") != null){
		out.println(WebService.getLocationByIP(request));
	}else if(request.getParameter("getWeather") != null){
		out.println(WebService.getWeather(request));
	}else{
		// ……其他接口
	}
 * @author frank
 *
 */
public class WebService {
	/**
	 * 通过  ip 地址获取请求所在地
	 * @param request
	 * @return
	 */
	public static String getLocationByIP(HttpServletRequest request){
		String ip = ajaxjs.net.Ip.getClientIP(request);// 获取 ip 地址
		
		String dbPath = ajaxjs.Util.Mappath(request, "WEB-INF/lib/17monipdb_v3.dat");
		IPDataHandler obj = new IPDataHandler(dbPath);
		String location = obj.findGeography(ip);
		String[] locations = location.split("	");
		String city = locations[locations.length - 1];
			
		return city.indexOf("局域网") != -1 ? "广州" :city;
	}
	
	/**
	 * 获取城市天气
	 * @param request
	 * @return
	 */
	public static String getWeather(HttpServletRequest request){
		String city = Request.getChinese(request, "city");
		System.out.println(city);
		return new Weather().getWeather(city);
	}
}
